//
//  RightShoesCollectionViewCell.m
//  Customized
//
//  Created by 陈凯旋 on 17/2/27.
//  Copyright © 2017年 陈凯旋. All rights reserved.
//

#import "RightShoesCollectionViewCell.h"
#import "BasicShoesSpu.h"
#import "UIImage+FitSizeScale.h"

#import "FootReportConstantKeyHeader.h"
#import "MacroKeyHeader.h"

#import <Masonry.h>
#import <UIImageView+WebCache.h>

@interface RightShoesCollectionViewCell()

@property(strong,nonatomic)UIImageView* backgroundImageView;
@property(strong,nonatomic)UIImageView* iconView;
@property(strong,nonatomic)UILabel* priceLabel;

@end
@implementation RightShoesCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    
    return self;
}



- (void)setupUI{
    
    
     self.backgroundImageView = [[UIImageView alloc]init];
    
    [self.contentView addSubview: self.backgroundImageView];
    
    [ self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(130);
        make.height.mas_equalTo(130);
        make.centerX.mas_equalTo(self.contentView);
        make.top.mas_equalTo(self.contentView);
    }];
    
    
    //等比例缩放图片
 
    CGFloat iconViewW = 124;
    CGFloat iconViewH = iconViewW * KMainShoesImageScale;
    
    self.iconView = [[UIImageView alloc]init];;
    [self.contentView addSubview:self.iconView];
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(iconViewW);
        make.height.mas_equalTo(iconViewH);
        make.center.mas_equalTo( self.backgroundImageView);
    }];
    
    self.priceLabel = [[UILabel alloc]init];
    self.priceLabel.textAlignment = NSTextAlignmentCenter;
    self.priceLabel.textColor = [UIColor colorWithRed:81/255.0 green:180/255.0 blue:180/255.0 alpha:1];
    self.priceLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.priceLabel];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.mas_equalTo(self.contentView);
        make.bottom.mas_equalTo(self.contentView).offset(-5);
        make.leading.mas_equalTo(self.contentView);
        
    }];
    
    
}



- (void)setModel:(BasicShoesSpu *)model{
    _model = model;
    
    self.priceLabel.text = [NSString stringWithFormat:@"¥%@",model.price];


    [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.imageUrls.firstObject] placeholderImage:nil options:SDWebImageRefreshCached completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        self.iconView.image = [UIImage imageCompressFitSizeScaleWithSourceImage:image targetSize:self.iconView.frame.size];
        
    }];
    

    
    self.backgroundImageView.image = [UIImage imageNamed:@"recommendBG"];
}



@end
